package com.study.d012Components;

import com.sun.javafx.scene.web.skin.HTMLEditorSkin;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;

/**Html编辑器
*@description
*@author xtayhame
*date 2020年3月18日
*version
*since v1.0
*/
public class HTMLEditorMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage stage) throws Exception {
		AnchorPane anchorPane= new AnchorPane();
		HBox hBox = new HBox(30);
		Button setButton = new Button("设置");
		Button getButton = new Button("获取");
		hBox.getChildren().addAll(setButton,getButton);

		HTMLEditor editor = new HTMLEditor();
		editor.setPrefSize(540, 300);
		//HTMLEditorSkin skin = new HTMLEditorSkin(editor);

		anchorPane.getChildren().addAll(hBox,editor);
		AnchorPane.setTopAnchor(hBox, 10.0);
		AnchorPane.setLeftAnchor(hBox, 10.0);

		AnchorPane.setTopAnchor(editor, 30.0);
		AnchorPane.setLeftAnchor(editor, 10.0);

		stage.setScene(new Scene(anchorPane, 600, 400));
		stage.show();


		setButton.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				String str="<html dir=\"ltr\"><head></head><body contenteditable=\"true\"><font size=\"5\">你好啊</font>"
						+ "<p><font size=\"5\"><br></font></p><p><font size=\"5\" face=\"Segoe UI\">奶粉都是</font></p>"
						+ "<p><font size=\"5\" face=\"Segoe UI\"><br></font></p><p><font size=\"5\" face=\"Segoe UI\"><br>"
						+ "</font></p><p><font size=\"5\" face=\"Segoe UI\">阿斯顿发sd</font></p>"
						+ "</body></html>";
				editor.setHtmlText(str);
			}
		});

		getButton.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				System.out.println(editor.getHtmlText());
			}
		});
	}
}
